package casa.depesos.app.com.activity;

import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;

import casa.depesos.app.com.BuildConfig;
import casa.depesos.app.com.databinding.ActivityAboutBinding;
import casa.depesos.app.com.http.ReqCallback;
import casa.depesos.app.com.http.bean.ScoreBean;
import casa.depesos.app.com.http.req.IsScoreReq;
import casa.depesos.app.com.utils.Update;
import casa.depesos.app.com.utils.Utils;

public class AboutActivity extends BaseActivity {

    ActivityAboutBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityAboutBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.top.top.setPadding(0, Utils.getStatusBarHeight(this), 0, 0);
        binding.top.back.setOnClickListener(v -> finish());
        binding.top.title.setText("Acerca de nosotros");

        binding.ver.setText("V" + BuildConfig.VERSION_NAME);
        score();
        binding.score.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

        binding.update.setOnClickListener(v -> {
            check();
        });
    }

    private void check() {
        new Update().check(this, true, true);
    }

    private void score() {
        new IsScoreReq().req(new ReqCallback<ScoreBean>() {
            @Override
            public void callback(boolean success, ScoreBean bean) {
                if (success && bean.isValid()) {
                    if ("1".equalsIgnoreCase(bean.info.open)) {
                        binding.score.setVisibility(View.VISIBLE);
                        binding.score.setOnClickListener(v -> {
                            WebActivity.startGooglePlay(bean.info.link);
                        });
                    } else {
                        binding.score.setVisibility(View.GONE);
                    }
                }
            }
        });
    }

    @Override
    protected boolean needPadding() {
        return false;
    }
}
